﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Channels;
using System.ServiceModel;

namespace NntpTransport
{
	public class NntpRequestChannelFactory : ChannelFactoryBase<IRequestChannel>
	{
		readonly BufferManager bufferManager;
		readonly MessageEncoderFactory encoderFactory;
		public readonly long MaxReceivedMessageSize;
		readonly string scheme;
		public readonly bool Streamed;

		public NntpRequestChannelFactory(NntpTransportBindingElement transportElement, BindingContext context) :
			base(context.Binding)
		{
			MessageEncodingBindingElement messageEncodingElement = context.BindingParameters.Remove<MessageEncodingBindingElement>();

			this.bufferManager = BufferManager.CreateBufferManager(transportElement.MaxBufferPoolSize, int.MaxValue);

			this.encoderFactory = messageEncodingElement.CreateMessageEncoderFactory();

			MaxReceivedMessageSize = transportElement.MaxReceivedMessageSize;
			this.scheme = transportElement.Scheme;
			Streamed = transportElement.Streamed;
		}
		
		protected override IRequestChannel OnCreateChannel(EndpointAddress address, Uri via)
		{
			return new NntpRequestChannel(this.bufferManager, this.encoderFactory, address, this, via);
		}


		protected override IAsyncResult OnBeginOpen(TimeSpan timeout, AsyncCallback callback, object state)
		{
			base.BeginOpen(timeout, callback, state);
			//throw new NotImplementedException();
		}

		protected override void OnEndOpen(IAsyncResult result)
		{
			base.OnEndOpen(result);
			//throw new NotImplementedException();
		}

		protected override void OnOpen(TimeSpan timeout)
		{
			//base.O
			throw new NotImplementedException();
		}
	}
}
